capture log close money
log using abs-rel-q3-money.txt, name(money) replace text

//  program:    abs-rel-q3-money.do
//  task:		analysis of absolute and relative inequality judgments
// 	input:		exp1.dta						
//	output:		none
//  project:    MEDEC experiment 1
//  author:     sam harper \ 25mar2013

//  #0
//  program setup

version 12
set linesize 80
clear all
macro drop _all

// #1
// bring in experiment 1 data

use exp1.dta, clear
datasignature confirm

// #2
// Scenario: decreasing abs, increasing relative

* first test for EMM by scenario status
regress q3money i.time##i.treatment##i.mag if scennum==2 | scennum==6, ///
	cluster(subject) cformat(%4.3f) vsquish
estimates store q3s26

* p-value for timeXtreatmentXmag = 0.050, so keep product term

* predicted margins, by scenario
margins time#treatment#mag, cformat(%4.3f)
marginsplot, legend(title("Experimental condition:", size(medsmall))) ///
	scheme(sj) xsc(r(-.2 1.2)) xtitle(Time) name(q3s26, replace) ///
	by(mag) ytitle("Dollars (min=0, max=100)", size(medsmall))  ///
	byopts(title("How much of your money to support program continuation?") ///
	note("Scenarios 2 and 6: Decreasing absolute, increasing relative inequality", size(small)))

* marginal effects
margins, dydx(treatment) over(mag time) cformat(%4.3f) post
lincom _b[1.treatment:0.mag#1.time] - _b[1.treatment:0.mag#0.time]
lincom _b[1.treatment:1.mag#1.time] - _b[1.treatment:1.mag#0.time]
lincom (_b[1.treatment:0.mag#1.time] - _b[1.treatment:0.mag#0.time]) ///
 	   - (_b[1.treatment:1.mag#1.time] - _b[1.treatment:1.mag#0.time])


// #3
// Scenario: constant absolute, increasing relative

* first test for EMM by scenario status
regress q3money i.time##i.treatment##i.mag if scennum==7 | scennum==8, ///
	cluster(subject) cformat(%4.3f) vsquish

* p-value for timeXtreatmentXmag = 0.290, so drop product term 
* and adjust for scenario
regress q3money i.time##i.treatment i.mag if scennum==7 | scennum==8, ///
	cluster(subject) cformat(%4.3f) vsquish
estimates store q3s78

* predicted margins
margins time#treatment mag, cformat(%4.3f)
qui margins time#treatment 
marginsplot, legend(title("Experimental condition:", size(medsmall))) ///
	title("How much of your money to support program continuation?", ///
	size(medsmall)) scheme(sj) xsc(r(-.2 1.2)) xtitle(Time) name(q3s78, replace) ///
	ytitle("Dollars (min=0, max=100)") ///
	note("Scenarios 7 and 8: Constant absolute, increasing relative inequality", size(small))

* marginal effects
margins, over(time) dydx(treatment) cformat(%4.3f) post
lincom _b[1.treatment:1.time] - _b[1.treatment:0.time]


// #4
// Scenario: decreasing abs, constant relative

* first test for EMM by scenario status
regress q3money i.time##i.treatment##i.mag if scennum==3 | scennum==4, ///
	cluster(subject) cformat(%4.3f) vsquish

* p-value for timeXtreatmentXmag = 0.052, so drop product term 
* and adjust for scenario	
regress q3money i.time##i.treatment i.mag if scennum==3 | scennum==4, ///
	cluster(subject) cformat(%4.3f) vsquish
estimates store q3s34

* predicted margins
margins time#treatment mag, cformat(%4.3f)
qui margins time#treatment 
marginsplot, legend(title("Experimental condition:", size(medsmall))) ///
	title("How much of your money to support program continuation?", ///
	size(medsmall)) scheme(sj) xsc(r(-.2 1.2)) xtitle(Time) name(q3s34, replace) ///
	ytitle("Dollars (min=0, max=100)") ///
	note("Scenarios 3 and 4: Decreasing absolute, constant relative inequality", size(small))

* marginal effects
margins, over(time) dydx(treatment) cformat(%4.3f) post
lincom _b[1.treatment:1.time] - _b[1.treatment:0.time]


// #5
// Scenario: decreasing abs, decreasing relative

* first test for EMM by scenario status
regress q3money i.time##i.treatment##i.mag if scennum==1 | scennum==5, ///
	cluster(subject) cformat(%4.3f) vsquish

* p-value for timeXtreatmentXmag = 0.959, so drop product term 
* and adjust for scenario
regress q3money i.time##i.treatment i.mag if scennum==1 | scennum==5, ///
	cluster(subject) cformat(%4.3f) vsquish
estimates store q3s15

* predicted margins
margins time#treatment mag, cformat(%4.3f)
qui margins time#treatment 
marginsplot, legend(title("Experimental condition:", size(medsmall))) ///
	title("How much of your money to support program continuation?", ///
	size(medsmall)) scheme(sj) xsc(r(-.2 1.2)) xtitle(Time) name(q3s15, replace) ///
	ytitle("Dollars (min=0, max=100)") ///
	note("Scenarios 1 and 5: Decreasing absolute, decreasing relative inequality", size(small))
	
* marginal effects
margins, over(time) dydx(treatment) cformat(%4.3f) post
lincom _b[1.treatment:1.time] - _b[1.treatment:0.time]


// #6
// Scenario: increasing abs, increasing relative

* first test for EMM by scenario status
regress q3money i.time##i.treatment##i.mag if scennum==9 | scennum==10, ///
	cluster(subject) cformat(%4.3f) vsquish

* p-value for timeXtreatmentXmag = 0.778, so drop product term 
* and adjust for scenario
regress q3money i.time##i.treatment i.mag if scennum==9 | scennum==10, ///
	cluster(subject) cformat(%4.3f) vsquish
estimates store q3s910

* predicted margins
margins time#treatment mag, cformat(%4.3f)
qui margins time#treatment 
marginsplot, legend(title("Experimental condition:", size(medsmall))) ///
	title("How much of your money to support program continuation?", ///
	size(medsmall)) scheme(sj) xsc(r(-.2 1.2)) xtitle(Time) name(q3s910, replace) ///
	ytitle("Dollars (min=0, max=100)") ///
	note("Scenarios 9 and 10: Increasing absolute, increasing relative inequality", size(small))

* marginal effects
margins, over(time) dydx(treatment) cformat(%4.3f) post
lincom _b[1.treatment:1.time] - _b[1.treatment:0.time]


// #6
// table of all effect estimates
esttab q3s26 q3s78 q3s34 q3s15 q3s910 using q3est.rtf, ///
	b(%5.2f) ci(%5.2f) ///
	keep(1.time 1.treatment 1.time#1.treatment 1.mag 1.time#1.mag 1.treatment#1.mag 1.time#1.treatment#1.mag _cons) ///
	collabels(Coef. 95\%CI) nostar not replace compress ///
	title("Money for support")
	
// #7
// put all results in a single graph, collapsing common scenarios
// and adjusting for scenario

* collapse scenarios
recode scennum (2 = 0 "Difference decreases, Small ratio increases") ///
	(6 = 1 "Differences decreases, Large ratio increase") ///
	(7 8 =2 "Difference constant, Ratio increases") ///
	(3 4 = 3 "Difference decreases, Ratio constant") ///
	(1 5 = 4 "Difference decreases, Ratio decreases") ///
	(9 10 = 5 "Difference increases, Ratio increases"), gen(grscen)
	
* predicted margins for inconsistent scenarios
qui regress q3money i.grscen##(i.time##i.treatment) i.mag if grscen<4, ///
	cluster(subject) cformat(%4.3f) vsquish
qui margins time#treatment, over(grscen)
marginsplot, xsc(r(-.2 1.2)) xtitle("") by(grscen) ///
	byopts(rows(1) title("Scenarios with inconsistent absolute and relative inequality trends", size(medsmall)) ///
	legend(off) graphregion(lcolor(white) fcolor(white))) ///
	ylab(0(20)100) subtitle(, size(vsmall) fcolor(white) lcolor(white)) ///
	ytitle("How much to support program continuation?"  "(min=$0...max=$100)", ///
	size(vsmall)) name(con, replace) fysize(42)

* predicted margins for consistent scenarios	
qui regress q3money i.grscen##(i.time##i.treatment) i.mag if grscen>3 ///
	& grscen<11, cluster(subject) cformat(%4.3f) vsquish
qui margins time#treatment, over(grscen)
marginsplot, xsc(r(-.2 1.2)) xtitle(Time) by(grscen) ///
	byopts(rows(1) title("Scenarios with consistent absolute and relative inequality trends", size(medsmall)) ///
	graphregion(lcolor(white) fcolor(white) margin(l=20 r=20))) ///
	legend(order(3 "shown raw data and difference measure of inequality" 4 "shown raw data and ratio measure of inequality") ///
	cols(1) rowgap(0.5) size(small) symxsize(8) ///
	title("Experimental condition:", size(small)) width(95)) ///
	subtitle(, size(vsmall) fcolor(white) lcolor(white)) ///
	ytitle("How much to support program continuation?"  "(min=$0...max=$100)", ///
	size(vsmall)) name(incon, replace) ylab(0(20)100)
	
graph combine con incon, rows(2) xsize(3.5) graphregion(lcolor(white) fcolor(white))

* predicted margins for exporting to R graphs	
qui regress q3money i.grscen##(i.time##i.treatment) i.mag if grscen<11, ///
	cluster(subject)
margins time#treatment, over(grscen)


log close money
exit
